using System;
using System.Collections.Generic;
using UnityEngine;

public class HFAssetsDownLoadManager : AbsHFSingleMonoBehaviour<HFAssetsDownLoadManager>
{
    private GameObject DownLoadManagerRoot;
    /// <summary>
    /// �ȴ�ִ���ļ�
    /// </summary>
    /// 
    private HFScriptMemPool<HFDownLoadGroup> m_MemPool;


    protected override void OnRunAwake()
    {
        base.OnRunAwake();
        m_MemPool = new HFScriptMemPool<HFDownLoadGroup>();
        DownLoadManagerRoot = new GameObject("DownLoadManagerRoot");
        UnityEngine.Object.DontDestroyOnLoad(DownLoadManagerRoot);
    }
    /// <summary>
    /// ��������
    /// </summary>
    /// <param name="downLoad"></param>
    /// <param name="downloadcallback"></param>
    /// <param name="downloadprogress"></param>
    public void AddTask(stDownLoadFileInfo info, Action<DownLoadedInfo> downloadcallback, Action<DownLoadProgress> downloadprogress)
    {
        List<stDownLoadFileInfo> stDownLoadFileInfos = new List<stDownLoadFileInfo>();
        stDownLoadFileInfos.Add(info);
        AddTask(stDownLoadFileInfos, downloadcallback, downloadprogress);
    }
    /// <summary>
    /// ��������
    /// </summary>
    /// <param name="downLoad"></param>
    /// <param name="downloadcallback"></param>
    /// <param name="downloadprogress"></param>
    public void AddTask(List<stDownLoadFileInfo> downLoad, Action<DownLoadedInfo> downloadcallback, Action<DownLoadProgress> downloadprogress) {
        bool isnew =false;
        HFDownLoadGroup group = m_MemPool.GetItem(out isnew);
        group.Init(DownLoadManagerRoot, 6, OnTaskFinish);
        group.AddDownLoadTaskList(downLoad, downloadcallback, downloadprogress);
    }

    private void OnTaskFinish(HFDownLoadGroup group)
    {
        m_MemPool.GiveBack(group);
    }
}
public enum EnGroupWeight
{
    High,
    Normal,
}
public struct stDownLoadFileInfo
{

    public int HashCode;
    public string MD5;
    public string FileName;
    public string UrlPathRoot;
    public string DownLoadPath;
    public string SavePathRoot;
    public int Size;
    /// <summary>
    /// ʧ�ܴ���
    /// </summary>
    public int failedCount;
    public EnGroupWeight Weight;
}